<div class="content scrolling">
    <form nz-form nzLayout="vertical">
        <nz-row>
            <nz-col [nzSpan]="12">
                <nz-form-item>
                    <nz-form-label>ID</nz-form-label>
                    <nz-form-control>{{consumer.id}}</nz-form-control>
                </nz-form-item>
            </nz-col>
            <nz-col [nzSpan]="12">
                <nz-form-item>
                    <nz-form-label>Description</nz-form-label>
                    <nz-form-control>{{consumer.description}}</nz-form-control>
                </nz-form-item>
            </nz-col>
        </nz-row>
        <nz-row>
            <nz-col [nzSpan]="12">
                <nz-form-item>
                    <nz-form-label>Scopes</nz-form-label>
                    <nz-form-control>{{scopes}}</nz-form-control>
                </nz-form-item>
            </nz-col>
            <nz-col [nzSpan]="12">
                <nz-form-item>
                    <nz-form-label>Groups</nz-form-label>
                    <nz-form-control>
                        {{groups}}
                        <span *ngIf="consumer.warnings" nz-tooltip [nzTooltipTitle]="warningText">
                                {{' '}}<i nz-icon nzType="warning" nzTheme="fill" class="orange" nz-tooltip nzTooltipTitle="{{warningText}}"></i>
                            </span>
                    </nz-form-control>
                </nz-form-item>
            </nz-col>
        </nz-row>
        <nz-row>
            <nz-col [nzSpan]="12">
                <nz-form-item>
                    <nz-form-label>Last authentication</nz-form-label>
                    <nz-form-control>{{consumer.last_authentication ? consumer.last_authentication : 'never'}}</nz-form-control>
                </nz-form-item>
            </nz-col>
            <nz-col [nzSpan]="12" *ngIf="consumer.auth_consumer_user.service_name || consumer.auth_consumer_user.service_type || consumer.auth_consumer_user.service_region || consumer.auth_consumer_user.service_ignore_job_with_no_region">
                <nz-form-item>
                    <nz-form-label>Service detail</nz-form-label>
                    <nz-form-control>
                        <ul>
                            <li>Name: {{consumer.auth_consumer_user.service_name}}</li>
                            <li>Type: {{consumer.auth_consumer_user.service_type}}</li>
                            <li>Region: {{consumer.auth_consumer_user.service_region}}</li>
                            <li>Ignore job with no region: {{consumer.auth_consumer_user.service_ignore_job_with_no_region}}</li>
                        </ul>
                    </nz-form-control>
                </nz-form-item>
            </nz-col>
        </nz-row>
        <nz-row>
            <nz-col [nzSpan]="24">
                <ul nz-menu nzMode="horizontal" *ngIf="menuItems?.size > 0">
                    <ng-container *ngFor="let entry of menuItems | forMap">
                        <li nz-menu-item [nzSelected]="selectedItem === entry.key" (click)="selectMenuItem(entry.key)">
                            {{entry.value}}
                        </li>
                    </ng-container>
                </ul>
            </nz-col>
        </nz-row>
        <nz-row>
            <nz-col [nzSpan]="24">
                <div class="field" [ngSwitch]="selectedItem">
                    <app-data-table *ngSwitchCase="'sessions'" [withFilter]="filterSessions" [withPagination]="5"
                                    [columns]="columnsSessions" [data]="consumer.sessions">
                    </app-data-table>
                    <ng-container *ngSwitchCase="'parent'">
                        <app-data-table *ngIf="consumer.parent" [columns]="columnsConsumers"
                                        [data]="[consumer.parent]">
                        </app-data-table>
                    </ng-container>
                    <ng-container *ngSwitchCase="'validity_periods'">
                        <app-data-table *ngIf="consumer.validity_periods" [columns]="columnsValidityPeriods"
                                        [data]="consumer.validity_periods">
                        </app-data-table>
                    </ng-container>
                    <app-data-table *ngSwitchCase="'children'" [withFilter]="filterChildren" [withPagination]="5"
                                    [columns]="columnsConsumers" [data]="consumer.children">
                    </app-data-table>
                </div>
            </nz-col>
        </nz-row>

        <nz-row>
            <nz-col [nzSpan]="24">
                <ng-container *ngIf="user.id === currentAuthSummary.user.id || currentAuthSummary.isAdmin()"
                              [ngSwitch]="consumer.type">
                    <ng-container *ngSwitchCase="'local'">
                        <button *ngIf="user.id === currentAuthSummary.user.id"
                                nz-button nzType="primary"
                                (click)="clickResetPassword()">Reset password</button>
                    </ng-container>
                    <ng-container *ngSwitchCase="'builtin'">
                        <button nz-button nzDanger nzType="primary"
                                nz-popconfirm nzPopconfirmTitle="Are you sure you want to delete this consumer ?"
                                (nzOnConfirm)="clickDelete()">Delete</button>
                        <div *ngIf="!consumer.disabled" class="floatRight">
                            <nz-button-group>
                                <button nz-button nzType="primary" (click)="clickRegen(false)">Regen
                                </button>
                                <button nz-button nzType="primary" nz-dropdown [nzDropdownMenu]="menu"
                                        nzPlacement="bottomRight">
                                    <i nz-icon nzType="down"></i>
                                </button>
                                <nz-dropdown-menu #menu="nzDropdownMenu">
                                    <ul nz-menu>
                                        <li nz-menu-item (click)="clickRegen(true)">
                                            {{'auth_consumer_regen_revoke' | translate }}
                                        </li>
                                    </ul>
                                </nz-dropdown-menu>
                            </nz-button-group>
                        </div>
                    </ng-container>
                    <ng-container *ngSwitchDefault>
                        <button nz-button nzDanger nzType="primary" *ngIf="user.id === currentAuthSummary.user.id"
                                [nzLoading]="loading"
                                nz-popconfirm nzPopconfirmTitle="Are you sure you want to detach this consumer ?"
                                (nzOnConfirm)="clickDetach()">
                            Detach
                        </button>
                    </ng-container>
                </ng-container>
                <button nz-button class="floatRight"
                        (click)="clickClose()">Close</button>
            </nz-col>
        </nz-row>
        <nz-row *ngIf="regenConsumerSigninToken">
            <nz-col [nzSpan]="24">
                <app-consumer-display-signin-token [consumer]="consumer"
                                                   [signinToken]="regenConsumerSigninToken">
                </app-consumer-display-signin-token>
            </nz-col>
        </nz-row>
    </form>

</div>

